<?php

namespace app\supplier\model\settings;

use app\common\model\settings\Shoptime as ShoptimeModel;
use app\common\model\settings\Region as RegionModel;
use think\facade\Db;

/**
 * 营业时间模型
 */
class Shoptime extends ShoptimeModel
{
	/**
	 * 获取列表
	 */
	public function getList($limit = 10,$SupplierId=0)
	{
		$list = $this->where('time_range','=',1)
		->where('shop_supplier_id','=',$SupplierId)
		->with(['supplier'])
		->order(['sort' => 'asc'])
		->paginate($limit)
		->each(function($item, $key){
			$relabel = '全国';
			$revaid = 0;
			$regionrs = RegionModel::withoutGlobalScope()->where('id','=',$item['area_id'])->find();
			if($regionrs){
				$revaid = $regionrs['id'];
				$relabel = $regionrs['name'];
			}
			$regionary = ['id'=>$revaid,'label'=>$relabel];
			$item->region = $regionary;
		});
		return $list;
	}

}